-- summon_explode
-- created by panyl
-- 召唤兽自爆

return {
    apply = function(prop, baseValue)
        return baseValue;
    end,

    -- 死亡触发
    trigger = function(who, prop, summon)
        if who.type ~= OBJECT_TYPE_USER or
            summon.type ~= OBJECT_TYPE_SUMMON then
            return;
        end

        -- TODO: 伤害需要策划完善
        local attack = summon:queryAttrib("attack");
        local damage = 2 * attack;
        for pos = 1, GRID_SIZE do
            local grid = DungeonM.getGridByPos(pos);
            local monster = grid.monster;

            -- 在场上的怪物
            if grid:isOpened() and monster and not monster:isDead() then
                SkillM.initSequence(summon, monster, 0);
                SkillM.getSequence(monster):delay(summon, monster, 0);
                CombatM.doDamage(summon, monster, damage, 0);
                print("summon_explode damage:" .. damage);
            end
        end

        return true;
    end,

    desc = function(prop)
        local str = PropM.query(prop[1], "desc");
        local summonId = tonumber(prop[2]);
        local name = SummonM.query(summonId, "name");

        return string.gsub(str, "{0}", name);
    end,

    record = function(target, prop, path)
        return false;
    end
};
